<!-- 企业f分成规则审核 -->
<template>
  <div class="home-page-content">
    <h3>企业收益规则审核</h3>
    <Form :model="formData" ref="FormRef" class="form-reset">
      <Row :gutter="30">
        <Col span="8">
          <CardMain itemName="公司名称">
            <FormItem prop="companyName">
              <Input
                v-model="formData.companyName"
                clearable
                placeholder="请输入公司名称"
              ></Input>
            </FormItem>
          </CardMain>
        </Col>
        <Col span="8">
          <CardMain itemName="收益规则">
            <FormItem prop="ruleRate">
              <Input
                v-model="formData.ruleRate"
                clearable
                placeholder="请输入收益规则"
              ></Input>
            </FormItem>
          </CardMain>
        </Col>
        <Col span="8">
          <CardMain itemName="证件号码">
            <FormItem prop="companyCardNumber">
              <Input
                clearable
                v-model="formData.companyCardNumber"
                placeholder="请输入证件号码"
              ></Input>
            </FormItem>
          </CardMain>
        </Col>
        <Col span="8">
          <CardMain itemName="更新时间">
            <FormItem>
              <DatePicker
                type="datetimerange"
                :value="datetime"
                @on-change="dateChange"
                placeholder="请选择时间"
                style="width: 100%"
                clearable
              ></DatePicker>
            </FormItem>
          </CardMain>
        </Col>
        <Col span="8">
          <CardMain itemName="审核状态">
            <FormItem>
              <Select
                v-model="formData.auditStatus"
                placeholder="请选择审核状态"
                class="company-select"
                clearable
              >
                <Option value="UnderReview">审核中</Option>
                <Option value="Pass">通过</Option>
                <Option value="NotPass">驳回</Option>
              </Select>
            </FormItem>
          </CardMain>
        </Col>
        <Col span="8">
          <CardMain itemName="组织范围">
            <FormItem prop="parentId">
              <CompanySelect
                :companyId.sync="formData.parentId"
                :companyChangeId="formData.parentId"
              />
            </FormItem>
          </CardMain>
        </Col>
        <Col span="24">
          <div class="action-search-btn">
            <Button type="primary" @click="queryList()">查询</Button>
            <Button type="primary" @click="formReset()">重置</Button>
          </div>
        </Col>
      </Row>
    </Form>
    <Row class="main-box">
      <Col span="24">
        <Table :columns="columns" :data="listData" :loading="isLoading">
          <template slot-scope="{ row }" slot="types">
            <Tag type="border" color="primary">标签</Tag>
          </template>
          <template slot-scope="{ row, index }" slot="file">
            <ViewImg
              isPreview
              isViewBtn
              isIcon
              errorMsg="规则说明"
              :fileList="formData.companyRuleFiles"
            ></ViewImg>
          </template>
          <template slot-scope="{ row, index }" slot="detail">
            <BtnText type="primary" @BtnClick="handleDetail(row)"
              >查看历史</BtnText
            >
          </template>
          <template slot-scope="{ row, index }" slot="action">
            <!-- <BtnText type="primary" @BtnClick="handleAction(row, 1)"
              >查看</BtnText
            > -->
            <BtnText
              type="green"
              v-if="row.auditStatus == 'UnderReview'"
              @BtnClick="handleAction(row, 2)"
              >通过</BtnText
            >
            <BtnText
              type="error"
              v-if="row.auditStatus == 'UnderReview'"
              @BtnClick="handleAction(row, 3)"
              >拒绝</BtnText
            >
          </template>
        </Table>
      </Col>
    </Row>
    <PageAtion
      v-if="total"
      :total="total"
      :size.sync="formData.size"
      :page.sync="formData.page"
      @pageSizeChange="pageSizeChange"
    />
  </div>
</template>

<script type="text/javascript">
import {
  GetCompanyRulePage, //查询企业分层规则列表
  CheckCompanyCheckRule, // 企业审核
} from "@/api/enterpriseInforManage.js";

export default {
  name: "sharingRuleAudit",
  components: {},
  data() {
    return {
      formData: {
        companyName: "",
        ruleRate: "",
        companyCardNumber: "",
        startDate: "",
        auditStatus: "",
        endDate: "",
        parentId: "",
        page: 1,
        size: 10,
      },
      columns: [
        {
          title: "公司名称",
          key: "companyName",
          minWidth: 120,
        },
        {
          title: "上级组织",
          key: "parentName",
          minWidth: 160,
        },
        {
          title: "证件号码",
          key: "companyCardNumber",
          minWidth: 140,
        },
        {
          title: "收益比例",
          key: "companyDivideIntoRuleValue",
          width: 100,
        },
        {
          title: "规则说明书",
          slot: "file",
          width: 160,
        },
        {
          title: "更新时间",
          key: "updateDateTime",
          width: 170,
        },
        {
          title: "变更历史",
          slot: "detail",
          width: 140,
        },
        {
          title: "审核状态",
          key: "auditStatusName",
          width: 100,
        },
        {
          title: "拒绝理由",
          key: "rejectReason",
          tooltip: true,
          ellipsis: true,
          width: 100,
        },
        {
          title: "操作",
          slot: "action",
          width: 200,
          align: "center",
        },
      ],
      listData: [],
      total: 0,
      isLoading: false,
      datetime: [],
    };
  },
  methods: {
    pageSizeChange() {
      this.getCompanyRuleData();
    },
    queryList() {
      this.formData.page = 1;
      this.getCompanyRuleData();
    },
    formReset() {
      this.formData.startDate = "";
      this.formData.endDate = "";
      this.formData.page = 1;
      this.formData.size = 10;
      this.datetime = [];
      this.$refs.FormRef.resetFields();
    },
    async getCompanyRuleData() {
      this.isLoading = true;
      let { data, total } = await GetCompanyRulePage(this.formData);
      this.listData = data;
      this.total = total;
      this.isLoading = false;
    },
    // 查看详情
    viewDetail(row) {
      this.$router.push({
        path: "/enterpriseInforDetail",
        query: {
          id: row.id,
        },
      });
    },
    // 查看规则详情
    handleDetail(row) {
      this.$router.push({
        path: "/changeRecord",
        query: {
          companyId: row.companyId,
          changeType: 1,
        },
      });
    },
    handleAction(row, types) {
      console.log(types, "types");
      if (types == 1) {
        this.$router.push({
          name: "enterpriseDetail",
          query: {
            id: row.id,
          },
        });
        return;
      }
      if (types == 2) {
        this.$Modal.confirm({
          title: "审核通过",
          content: "<p>确定审核通过吗？</p>",
          loading: true,
          onOk: async () => {
            let params = {
              id: row.id,
              auditStatus: 2,
            };
            let that = this;
            try {
              let data = await CheckCompanyCheckRule(params);
              this.$tips(
                {
                  iconName: "icon_1",
                  text: "审核通过",
                },
                function handleClose(data) {
                  that.getCompanyRuleData();
                }
              );
              this.$Modal.remove();
            } catch (error) {
              this.$Modal.remove();
            }
          },
        });
      }
      if (types == 3) {
        let that = this;

        this.$tips(
          {
            iconName: "icon_2",
            text: "审核已拒绝",
            isArgument: true,
          },
          // 点击确定的按钮回调
          async function handleSubmit(ev, value) {
            try {
              let params = {
                id: row.id,
                auditStatus: 3,
                rejectReason: value,
              };
              let data = await CheckCompanyCheckRule(params);
              ev.remove();
              that.$tips(
                {
                  iconName: "icon_2",
                  text: "审核拒绝",
                },
                function handleClose(data) {
                  that.getCompanyRuleData();
                }
              );
            } catch (error) {
              ev.remove();
            }
          }
        );
      }
    },
    dateChange(ev) {
      this.formData.startDate = ev[0];
      this.formData.endDate = ev[1];
    },
  },
  mounted() {
    this.getCompanyRuleData();
  },
};
</script>

<style lang="less" scoped>
.home-index-content {
  h3 {
    font-size: 18px;
  }
}

.company-select {
  margin-right: 10px;
}
</style>
